﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_UpdateOnlineInfo]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_UpdateOnlineInfo];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_UpdateOnlineInfo]
    @username	nvarchar(25),
    @hostaddr   nvarchar(50),
    @sessionid  nvarchar(64) 
            
/*

============================================================
功能:    员工登陆 判断是否登陆成功
参数:
    @username            nvarchar(25)        :    登陆名
    @hostaddr              nvarchar(50),        :    登陆主机IP
    @sessionid             nvarchar(50)         ;    Session ID

============================================================

*/

AS
BEGIN
SET NOCOUNT ON

DECLARE @time datetime;
SET @time = getdate();

-- Update the existing data first
UPDATE
	dbo.UDS_Online
SET
	logintime = @time,
	activetime = @time,
	ipaddr = @hostaddr,
	authkey = @sessionid
WHERE
	Username=@username;

IF ( @@ROWCOUNT = 0 )
BEGIN
	-- No exists, create a new record for the user then
	INSERT INTO dbo.UDS_Online (username, logintime, activetime, ipaddr, authkey)
	VALUES(@username, @time, @time, @hostaddr, @sessionid)
END

END
GO